
import request from '../../components/Request/index'
import {notification} from 'ant-design-vue';
/**
 * 提交登录信息
 * @param values
 * @returns {Promise<void>}
 */
export async function submit(values) {
  let res = await request.post({
    url: './public/login.do',
    data: values
  });

  if (res.success) {
    let returnUrl = getQueryString('returnUrl');
    if (returnUrl == null) {
      window.location.href = './main.html';
    } else {
      window.location.href = returnUrl + (returnUrl.indexOf('?', 0) > 0 ? '&' : '?') + '_token=' + res.data;
    }
  } else {
    notification['error']({ message: '登录消息', description: res.msg });
  }
}

/**
 * 根据变量名获取匹配值
 */
function getQueryString(name) {
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  var r = window.location.search.substr(1).match(reg);
  if (r != null) return unescape(r[2]); return null;
}

/**
 * 获取应用系统参数信息
 * @returns {Promise<*>}
 */
export async function listCfg() {
  let res = await request.post({
    url: './public/listCfg.do'
  });
  return res.data;
}
